﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Core;
using SmartSpace;
using SmartSapce.ServiceLocation;

namespace SmartSpace.WebApp._console.core
{
    public partial class role_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                PagedList<Role> roles = service.GetRoles(0, 999);

                _ctlGridRole.DataSource = roles;
                _ctlGridRole.DataBind();
            }
        }

        protected void _ctlCmdDelete_Click(object sender, EventArgs e)
        {
            LinkButton btn = sender as LinkButton;
            Guid id = new Guid(btn.CommandArgument);
            ICoreService service = ServiceLocator.Get<ICoreService>();
            Role role = new Role();
            role.Id = id;
            if (service.DeleteRole(role))
            {
                Response.Redirect(Request.Url.AbsoluteUri);
            }
            else
            {
                Response.Redirect(Request.Url.AbsoluteUri);
            }
        }
    }
}